package com.ruoyi.system.aop;

import com.ruoyi.system.domain.SysLogs;
import com.ruoyi.system.service.SysLogsService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Component
@Aspect
public class MyAop {

    @Autowired
    HttpServletRequest request;
    @Autowired
    SysLogsService sysLogsService;

    @Around("execution(* com.ruoyi.system.controller.*.*(..))")
    public Object myaop(ProceedingJoinPoint pjp) throws Throwable {

        String ip = request.getRemoteAddr();
        String uri = request.getRequestURI();
        Date date = new Date();

        SysLogs sysLogs = new SysLogs();
        sysLogs.setIp(ip);
        sysLogs.setUrl(uri);
        sysLogs.setCreated(date);

        boolean b = sysLogsService.saveLogs(sysLogs);
        Object proceed = pjp.proceed();
        return proceed;

    }

}
